package com.itheima.service.backend.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.common.entity.PageResult;
import com.itheima.mapper.backend.CheckMapper;
import com.itheima.pojo.CheckItem;
import com.itheima.service.backend.CheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CheckServiceImpl implements CheckService {
    @Autowired
    private CheckMapper checkMapper;
    @Override
    public void add(CheckItem checkItem) {
        checkMapper.add(checkItem);
    }

    @Override
    public void delete(Integer id) {
        checkMapper.delete(id);

    }

    @Override
    public List<Integer> findCheckItemIdsByCheckGroupId(Integer checkgroupId) {
        return checkMapper.findCheckItemIdsByCheckGroupId(checkgroupId);
    }

    @Override
    public void edit(CheckItem checkItem) {
        checkMapper.edit(checkItem);
    }

    @Override
    public PageResult page(Integer page, Integer pageSize, String name) {
        //1. 设置分页参数
        PageHelper.startPage(page,pageSize);

        //2. 执行查询
        List<CheckItem> checkItemList = checkMapper.list(name);
        Page<CheckItem> pageBean = (Page<CheckItem>) checkItemList;


        //3. 封装PageBean对象
        PageResult pageResult = new PageResult(pageBean.getTotal(),pageBean.getResult());
        return pageResult;
    }

    @Override
    public List<CheckItem> list() {
        return checkMapper.findAll();
    }

    @Override
    public CheckItem findById(Integer id) {
        return checkMapper.findById(id);
    }
}
